package com.qingxin.park.service;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qingxin.park.entity.BatchProducts;
import com.qingxin.park.entity.BatchProductsView;
import com.qingxin.park.entity.FarmPark;
import com.qingxin.park.entity.ParkBlockPlant;
import com.qingxin.park.entity.ParkBlockPlantView;
import com.qingxin.qrCode.entity.QrNum;
import com.qingxin.qrCode.service.QrNumService;
import com.qingxin.sys.dao.Querier;
import com.qingxin.sys.dao.Updater;
import com.qingxin.sys.entity.LoginUser;
import com.qingxin.sys.entity.MyUploadFileParam;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.mvc.Pager;
import com.qingxin.sys.mvc.SysError;
import com.qingxin.sys.service.BaseService;
import com.qingxin.sys.support.SystemCfg;
import com.qingxin.sys.support.UploadFile;
import com.qingxin.sys.utils.BeanUtil;
import com.qingxin.sys.utils.StringUtils;


/**
 * 批次产品表（追溯物）
 * @author Administrator
 *
 */
@Service
public class BatchProductsService extends BaseService<BatchProducts, String> {
	
	@Autowired
	private FarmParkService farmParkService;
	@Autowired
	private ParkBlockPlantService parkBlockPlantService;
//	@Autowired
//	private SysConfigService sysConfigService;
//	@Autowired
//	private CropsService cropsService;
//	@Autowired
//	private ProductionLinkService productionLinkService;
	
	@Autowired
	private BatchProductsReportService batchProductsReportService;
	
	@Autowired
	private QrNumService qrNumService;
	
//	@Autowired
//	private MaterialService materialService;
	
	
	
	/**
	 * 列表数据
	 * @param parkid
	 * @param blockid
	 * @param pbn
	 * @param begin
	 * @param end
	 * @param pageParam
	 * @param loginUser
	 * @return
	 */
	public Pager list(String companyid, String parkid,String blockid,String pdttype,String pbn,
			Date begin, Date end, PageParam pageParam, LoginUser loginUser){
		Querier querier = Querier.create("select new com.qingxin.park.entity.BatchProductsView(" +
				"p.pdtid, p.pdtname, p.pbn, p.status, p.beginTime, p.endTime, p.amount, p.workerName, p.cropName, p.blockName, p.units, p.pdtcode)" +
				" from BatchProductsView p where 1=1");
		
		if(StringUtils.isNotEmpty(companyid)){
			querier.append(" and p.companyid=:companyid");
			querier.setParam("companyid", companyid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else if(StringUtils.isNotEmpty(parkid)){
			querier.append(" and p.parkid=:parkid");
			querier.setParam("parkid", parkid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else{
			querier.append(" and p.blockid=:blockid");
			querier.setParam("blockid", blockid);
		}
		
		if(StringUtils.isNotEmpty(pdttype)){
			querier.append(" and p.pdttype=:pdttype");
			querier.setParam("pdttype", pdttype);
		}
		
		if(StringUtils.isNotEmpty(pbn)){
			querier.append(" and p.pbn=:pbn");
			querier.setParam("pbn", pbn);
		}
		
		if(begin != null){
			querier.append(" and p.endTime >= :beginTime ");
			querier.setParam("beginTime", begin);
		}
		if(end != null){
			querier.append(" and p.endTime <= :endTime ");
			querier.setParam("endTime", end);
		}
		
		querier.append(pageParam.getOrderby(" order by p.createTime desc"));
		
		Pager pager = pageByQuerier(querier, pageParam);
		return pager;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<BatchProductsView> listForExport(String companyid, String parkid,
			String blockid, String pdttype, Date begin, Date end, LoginUser loginUser){
		Querier querier = Querier.create("from BatchProductsView p where p.pdttype=:pdttype ");
		querier.setParam("pdttype", pdttype);
		
		if(StringUtils.isNotEmpty(companyid)){
			querier.append(" and p.companyid=:companyid");
			querier.setParam("companyid", companyid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else if(StringUtils.isNotEmpty(parkid)){
			querier.append(" and p.parkid=:parkid");
			querier.setParam("parkid", parkid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else{
			querier.append(" and p.blockid=:blockid");
			querier.setParam("blockid", blockid);
		}
		
		if(StringUtils.isNotEmpty(pdttype)){
			querier.append(" and p.pdttype=:pdttype");
			querier.setParam("pdttype", pdttype);
		}
		
		if(begin != null){
			querier.append(" and p.endTime >= :beginTime ");
			querier.setParam("beginTime", begin);
		}
		if(end != null){
			querier.append(" and p.endTime <= :endTime ");
			querier.setParam("endTime", end);
		}
		
		querier.append(" order by p.createTime desc");
		
		List<BatchProductsView> list = listByQuerier(querier);
		return list;
	}
	
	
	/**
	 * 含有速测数据的
	 * @param companyid
	 * @param parkid
	 * @param blockid
	 * @param pdttype
	 * @param pbn
	 * @param begin
	 * @param end
	 * @param pageParam
	 * @param loginUser
	 * @return
	 */
	public Pager listDetectionData(String companyid, String parkid,String blockid,String pdttype,String pbn,
			Date begin, Date end, PageParam pageParam, LoginUser loginUser){
		Querier querier = Querier.create("select new com.qingxin.park.entity.BatchProductsView(" +
				"p.pdtid, p.pdtname, p.pbn, p.status, p.beginTime, p.endTime, p.amount, p.workerName, p.cropName, p.blockName, p.units, p.pdtcode)" +
				" from BatchProductsView p where ncsc = '1'");
		if(StringUtils.isNotEmpty(companyid)){
			querier.append(" and p.companyid=:companyid");
			querier.setParam("companyid", companyid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else if(StringUtils.isNotEmpty(parkid)){
			querier.append(" and p.parkid=:parkid");
			querier.setParam("parkid", parkid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else{
			querier.append(" and p.blockid=:blockid");
			querier.setParam("blockid", blockid);
		}
		
		if(StringUtils.isNotEmpty(pdttype)){
			querier.append(" and p.pdttype=:pdttype");
			querier.setParam("pdttype", pdttype);
		}
		
		if(StringUtils.isNotEmpty(pbn)){
			querier.append(" and p.pbn=:pbn");
			querier.setParam("pbn", pbn);
		}
		
		if(begin != null){
			querier.append(" and p.endTime >= :beginTime ");
			querier.setParam("beginTime", begin);
		}
		if(end != null){
			querier.append(" and p.endTime <= :endTime ");
			querier.setParam("endTime", end);
		}
		
		querier.append(pageParam.getOrderby(" order by p.createTime desc"));
		
		Pager pager = pageByQuerier(querier, pageParam);
		return pager;
	}
	
	
	/**
	 * 列表数据
	 * @param parkid
	 * @param blockid
	 * @param pbn
	 * @param begin
	 * @param end
	 * @param pageParam
	 * @param loginUser
	 * @return
	 */
	public Pager list(String parkid, String blockid, String pbn,
			Date begin, Date end, PageParam pageParam, LoginUser loginUser){
		Querier querier = Querier.create("select new com.qingxin.park.entity.BatchProductsView(" +
				"p.pdtid, p.pdtname, p.pbn, p.status, p.beginTime, p.endTime, p.amount, p.workerName, p.cropName, p.blockName, p.units, p.pdtcode)" +
				" from BatchProductsView p where 1=1");
		if(StringUtils.isNotEmpty(parkid)){
			querier.append(" and p.parkid=:parkid");
			querier.setParam("parkid", parkid);
			
			if(!SystemCfg.isDataAdminUser(loginUser)){
				querier.append(" and p.blockid in (select distinct v.parkBlock.blockid from SysUserBlockRel v where v.sysUser.userid=:userid)");
				querier.setParam("userid", loginUser.getUserid());
			}
		}else{
			querier.append(" and p.blockid=:blockid");
			querier.setParam("blockid", blockid);
		}
		
		if(StringUtils.isNotEmpty(pbn)){
			querier.append(" and p.pbn=:pbn");
			querier.setParam("pbn", pbn);
		}
		
		if(begin != null){
			querier.append(" and p.endTime >= :beginTime ");
			querier.setParam("beginTime", begin);
		}
		if(end != null){
			querier.append(" and p.endTime <= :endTime ");
			querier.setParam("endTime", end);
		}
		
		querier.append(pageParam.getOrderby(" order by p.createTime desc"));
		
		Pager pager = pageByQuerier(querier, pageParam);
		return pager;
	}
	
	
	/**
	 * 根据追溯码获取产品信息
	 * @param pbn
	 * @return
	 */
	public BatchProducts getByPbn(String pbn){
		BatchProducts products = (BatchProducts) getByHql("from BatchProducts where pbn=? order by createTime desc", pbn);
		return products;
	}
	
	
	/**
	 * 根据产品编码获取产品信息
	 * @param pdtcode
	 * @return
	 */
	public BatchProductsView getByPdtcode(String pdtcode){
		BatchProductsView products = (BatchProductsView) getByHql("from BatchProductsView where pdtcode=? order by createTime desc", pdtcode);
		return products;
	}
	
	
	/**
	 * 获取最新产品信息
	 * @return
	 */
	public BatchProducts getLastestProducts(){
		BatchProducts products = (BatchProducts) getByHql("from BatchProducts order by createTime desc");
		return products;
	}
	
	
	/**
	 * 获取产品信息视图对象
	 * @param pdtid
	 * @return
	 */
	public BatchProductsView getProductsView(String pdtid){
		BatchProductsView products = (BatchProductsView) getByHql("from BatchProductsView where pdtid=?", pdtid);
		return products;
	}
	
	
	/**
	 * 根据追溯码获取产品信息
	 * @param pbn
	 * @return
	 */
	public BatchProductsView getProductsViewByPbn(String pbn){
		BatchProductsView products = (BatchProductsView) getByHql("from BatchProductsView where pbn=? order by createTime desc", pbn);
		return products;
	}
	
	
	/**
	 * 添加产品信息
	 * @param products
	 * @param plantid
	 * @param loginUser
	 * @param request
	 * @return
	 */
	public synchronized SysError add(BatchProducts products, String plantid, MyUploadFileParam uploadFileParam, LoginUser loginUser, HttpServletRequest request){
		ParkBlockPlantView plant = parkBlockPlantService.getPlantView(plantid);
		if(plant == null){
			return new SysError("该地块没有可用种植信息，请先到“种植管理”模块添加种植信息");
		}
		products.setParkBlockPlant(new ParkBlockPlant(plantid));
		FarmPark farmPark = farmParkService.get(plant.getParkid());
		
		Date now = new Date();
		products.setCreateTime(now);
		products.setUpdateTime(now);
		products.setCreateBy(loginUser.getLogin_name());
		products.setUpdateBy(loginUser.getLogin_name());
		
		products.setParkid(plant.getParkid());
		products.setCompanyid(farmPark.getCompanyid());
		
		products.setBeginTime(plant.getBeginTime());
		if(products.getEndTime() == null){
			products.setEndTime(new Date());
		}
		
		try {
			//改为绑定二维码
			//products.setPbn(createPbn());
		} catch (Exception e) {
			logger.error("生成追溯码失败", e);
			return new SysError("生成追溯码失败，请联系管理员解决该问题");
		}
		
		if(StringUtils.isNotEmpty(products.getPdtimg())){
			UploadFile.moveTmpTo(products.getPdtimg(), UploadFile.DIR_PRODUCTS_IMG);
		}
		
		String max_pdtcode = (String) getByHql("select pdtcode from BatchProducts order by pdtcode desc");
		if(max_pdtcode == null){
			max_pdtcode = "1000000";
		}else {
			max_pdtcode = Integer.toString(Integer.parseInt(max_pdtcode)+1);
		}
		products.setPdtcode(max_pdtcode);
		
		products.setNcsc("0");
		products.setNcscTime(new Date());
		
		this.save(products);
		
		batchProductsReportService.add(products.getPdtid(), uploadFileParam, loginUser);
		
		return null;
	}
	
	
//	/**
//	 * 生成追溯码，组成格式：头标记（2位）+年月日（3位）+序号（5位），长度为10位
//	 * @return
//	 */
//	public synchronized String createPbn() throws Exception {
//		String pbn_syscode = sysConfigService.getConfigValueIgnoreCache("pbn_syscode");
//		int pbn_increment = Integer.parseInt(sysConfigService.getConfigValueIgnoreCache("pbn_increment"));
//		if(!pbn_syscode.matches("[0-9A-Za-z]{2}")){
//			throw new Exception("系统参数表【sys_config/pbn_syscode】值配值错误，必须由两位字母或数字组成");
//		}
//		
//		StringBuilder pbn = new StringBuilder(pbn_syscode);
//		//年月日以36进制形式各占一位
//		DateTime dateTime = new DateTime();
//		int year = ((dateTime.getYear() + 1) % 100) % Character.MAX_RADIX;
//		if(year >= Character.MAX_RADIX){
//			year = 0;
//		}
//		pbn.append(Integer.toString(year, Character.MAX_RADIX));
//		pbn.append(Integer.toString(dateTime.getMonthOfYear(), Character.MAX_RADIX));
//		pbn.append(Integer.toString(dateTime.getDayOfMonth(), Character.MAX_RADIX));
//		
//		pbn_increment++;
//		if(pbn_increment<1 || pbn_increment > 99999){
//			pbn_increment = 1;
//		}
//		pbn.append(String.format("%05d", pbn_increment));
//		
//		sysConfigService.updateIgnoreCache("pbn_increment", (""+pbn_increment), null, false);
//		
//		return pbn.toString().toUpperCase();
//	}
	
	
	/**
	 * 修改产品信息
	 * @param products
	 * @param loginUser
	 * @param request
	 * @return
	 */
	public SysError update(BatchProducts products, MyUploadFileParam uploadFileParam, LoginUser loginUser, HttpServletRequest request){
		BatchProducts old = getSafeEntity(products.getPdtid());
		if(old==null){
			return new SysError("参数错误");
		}
		
		ParkBlockPlantView plant = parkBlockPlantService.getPlantView(old.getParkBlockPlant().getPlantid());
		if(plant == null){
			return new SysError("该地块没有可用种植信息，请先到“种植管理”模块添加种植信息");
		}
		
		products.setBeginTime(plant.getBeginTime());
		if(products.getEndTime() == null){
			products.setEndTime(new Date());
		}
		
		if(StringUtils.isNotEmpty(products.getPdtimg()) && !products.getPdtimg().equals(old.getPdtimg())){
			UploadFile.moveTmpTo(products.getPdtimg(), UploadFile.DIR_PRODUCTS_IMG);
		}
		
		String fields = "pdtname,status,beginTime,endTime,amount,worker,workerName,remark,pdtimg";
		BeanUtil.setTargetFields(old, products, fields, true);
		
		old.setUpdateBy(loginUser.getLogin_name());
		old.setUpdateTime(new Date());
		
		Updater<BatchProducts> updater = new Updater<>(old, fields+",updateBy,updateTime");
		this.update(updater);
		
		batchProductsReportService.add(products.getPdtid(), uploadFileParam, loginUser);
		
		return null;
		
	}
	
	
	/**
	 * 添加绑定二维码
	 * @param pdtid
	 * @param qrnumid
	 * @return
	 */
	public Object addBindQrcode(String pdtid, String qrnumid){
		QrNum qrNum = qrNumService.get(qrnumid);
		if(qrNum == null || !"0".equals(qrNum.getDeltype())){
			return new SysError("二维码信息不存在");
		}
		if(!"0".equals(qrNum.getIs_activation())){
			return new SysError("二维码已被使用，请更换其他二维码");
		}
		
		BatchProducts old = getSafeEntity(pdtid);
		if(old==null){
			return new SysError("参数错误");
		}
		old.setPbn(qrNum.getCode());
		
		Updater<BatchProducts> updater = new Updater<>(old, "pbn");
		this.update(updater);
		
		qrNumService.updateActivation(qrnumid, "1");
		
		return null;
	}
	
	
	/**
	 * 更新农残速测数据状态
	 * @param pdtid
	 * @return
	 */
	public Object updateNcsc(String pdtid){
		BatchProducts old = getSafeEntity(pdtid);
		if(old==null){
			return new SysError("参数错误");
		}
		old.setNcsc("1");
		old.setNcscTime(new Date());
		
		Updater<BatchProducts> updater = new Updater<>(old, "ncsc,ncscTime");
		this.update(updater);
		return null;
	}
	
	
	/**
	 * 删除产品信息
	 * @param pdtids
	 * @param loginUser
	 * @param request
	 * @return
	 */
	public Object delete(String[] pdtids, LoginUser loginUser, HttpServletRequest request){
		for(String pdtid : pdtids){
			BatchProducts products = get(pdtid);
			if(products==null){
				continue;
			}
			
			this.delete(products);
		}
		
		return null;
	}
	
	
	
//	/**
//	 * 获取追溯数据
//	 * @param pbn
//	 * @param useGroup
//	 * @return
//	 */
//	public TraceData getTraceData(String pbn, boolean useGroup){
//		return getTraceDataAbsImg(pbn, useGroup);
//	}
//	
//	
//	/**
//	 * 获取追溯数据
//	 * @param pbn
//	 * @param useGroup
//	 * @return
//	 */
//	@SuppressWarnings("unchecked")
//	public TraceData getTraceDataAbsImg(String pbn, boolean useGroup){
//		BatchProductsView products = getProductsViewByPbn(pbn);
//		if(products == null){
//			return new TraceData(404, "没有找到相关信息");
//		}
//		
//		TraceData traceData = new TraceData(200, null);
//		traceData.setParkName(products.getParkName());
//		traceData.setBlockName(products.getBlockName());
//		
//		FarmPark farmPark = farmParkService.get(products.getParkid());
//		if(farmPark != null){
//			TracePark tracePark = new TracePark(farmPark.getParkid(), farmPark.getParkName(),
//					farmPark.getParkAddress(), farmPark.getContactPerson(), farmPark.getPhone(),
//					farmPark.getMobile(), farmPark.getEmail(), farmPark.getWechat(),
//					farmPark.getParkLevel(), farmPark.getLat(), farmPark.getLng());
//			tracePark.setImg(UploadFile.getFileUrl(UploadFile.DIR_FARM_IMG, farmPark.getLogoUrl()));
//			tracePark.setRemark(farmPark.getRemark());
//			traceData.setPark(tracePark);
//		}
//		
//		traceData.setPdtid(products.getPdtid());
//		traceData.setPdtname(products.getPdtname());
//		if(StringUtils.isNotEmpty(products.getPdtimg())){
//			traceData.setPdtimg(UploadFile.getFileUrl(UploadFile.DIR_PRODUCTS_IMG, products.getPdtimg()));
//		}else {
//			Crops crops = cropsService.get(products.getCropid());
//			if(crops != null && StringUtils.isNotEmpty(crops.getCropImg())){
//				traceData.setPdtimg(UploadFile.getFileUrl(UploadFile.DIR_CROP_IMG, crops.getCropImg()));
//			}
//		}
//		traceData.setPbn(products.getPbn());
//		traceData.setBeginDate(DateUtil.fmtDate(products.getBeginTime()));
//		traceData.setEndDate(DateUtil.fmtDate(products.getEndTime()));
//		traceData.setAmount(products.getAmount());
//		traceData.setCrop(products.getCropName());
//		traceData.setUnits(products.getUnits());
//		
//		
//		Querier querier = Querier.create("from ProRecord p" +
//				" where p.keyjob='1' and p.parkBlockPlant.plantid=:plantid" +
//				" and p.workdate>=:beginTime" +
//				" and p.workdate<=:endTime" +
//				" order by p.workdate desc");
//		querier.setParam("plantid", products.getPlantid());
//		querier.setParam("beginTime", products.getBeginTime());
//		querier.setParam("endTime", products.getEndTime());
//		
//		List<ProRecord> list = listByQuerier(querier);
//		List<TraceRecord> records = new ArrayList<>();
//		List<TraceGroup> groups = new ArrayList<>();
//		
//		TraceGroup jiben = new TraceGroup("基本生产信息");
//		TraceGroup shifei = new TraceGroup("施肥作业");
//		TraceGroup zhibao = new TraceGroup("植保作业");
//		TraceGroup caishou = new TraceGroup("采收作业");
//		
//		if(list != null){
//			for(ProRecord proRecord : list){
//				TraceRecord record = new TraceRecord(proRecord.getRecordid(),
//						proRecord.getLinkName(), DateUtil.fmtDate(proRecord.getWorkdate()),
//						"1".equals(proRecord.getWorktime())?"上午":"下午", proRecord.getWorkerName(),
//						"0".equals(proRecord.getPlantStatus())?"未成熟":"已成熟", proRecord.getRemark());
//				
//				String linkIcon = productionLinkService.getProlinkIcon(proRecord.getLinkid());
//				if(StringUtils.isNotEmpty(linkIcon)){
//					record.setLinkIcon( UploadFile.getFileUrl(UploadFile.DIR_PROLINK_IMG, linkIcon));
//				}
//				
//				switch (proRecord.getLinkType()) {
//				case 0: record.setLinkType("基本生产信息"); break;
//				case 1: record.setLinkType("施肥作业"); break;
//				case 2: record.setLinkType("植保作业"); break;
//				case 3: record.setLinkType("采收作业"); break;
//				}
//				
//				//图片
//				Set<ProRecordImgs> imgSet = proRecord.getProRecordImgses();
//				for(ProRecordImgs img : imgSet){
//					record.addImg(new TraceRecordImg(img.getImgName(), UploadFile.getFileUrl(UploadFile.DIR_PRORECORD_IMG, img.getImgPath())));
//				}
//				
//				//物资
//				Set<ProRecordMaterial> proRecordMaterials = proRecord.getProRecordMaterials();
//				for(ProRecordMaterial recordMaterial : proRecordMaterials){
//					Material material = materialService.get(recordMaterial.getMaterialid());
//					if(material != null){
//						record.setMat(new TraceRecordMaterial(material.getMaterialName(), material.getFactory(), UploadFile.getFileUrl(UploadFile.DIR_MATERIAL_IMG, material.getMaterialImg())));
//						break;
//					}
//				}
//				
//				if(useGroup){
//					switch (proRecord.getLinkType()) {
//					case 0: jiben.addRecord(record); break;
//					case 1: shifei.addRecord(record); break;
//					case 2: zhibao.addRecord(record); break;
//					case 3: caishou.addRecord(record); break;
//					}
//				}else {
//					records.add(record);
//				}
//			}
//		}
//		if(useGroup){
//			if(jiben.getRecords().size()>0){
//				groups.add(jiben);
//			}
//			if(shifei.getRecords().size()>0){
//				groups.add(shifei);
//			}
//			if(zhibao.getRecords().size()>0){
//				groups.add(zhibao);
//			}
//			if(caishou.getRecords().size()>0){
//				groups.add(caishou);
//			}
//			traceData.setGroups(groups);
//		}else {
//			traceData.setRecords(records);
//		}
//		
//		List<TraceReport> reports = new ArrayList<>();
//		List<BatchProductsReport> reportList = batchProductsReportService.listProductsReport(products.getPdtid());
//		if(reportList !=null){
//			for(BatchProductsReport report : reportList){
//				reports.add(new TraceReport(report.getReportName(), UploadFile.getFileUrl(UploadFile.DIR_PRODUCTS_IMG, report.getReportUrl())));
//			}
//		}
//		if(reports.size() > 0){
//			traceData.setReports(reports);
//		}
//		
//		return traceData;
//	}
	
	
}
